//package com.spring.security.config.filter;
//
//import com.spring.security.config.exeception.VerificationCodeException;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.security.authentication.AuthenticationServiceException;
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
//import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
//import org.springframework.stereotype.Component;
//import org.springframework.util.StringUtils;
//import org.springframework.web.filter.OncePerRequestFilter;
//
//import javax.servlet.FilterChain;
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
///**
// * @Author wsh
// * @Date 2020/7/14 17:14
// * @Desc 校验验证码
// */
//@Component
//@Slf4j
//public class VerificationCodeFilter extends OncePerRequestFilter {
//
//    private String defaultFilterProcessUrl = "/login";
//
//    @Override
//    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
//        log.info("当前请求地址：{}",request.getServletPath());
//        log.info("当前请求的方法：{}",request.getMethod());
//        if ("POST".equalsIgnoreCase(request.getMethod())
//                && defaultFilterProcessUrl.equals(request.getServletPath())){
//            String code = request.getParameter("captcha");
//            String genCaptcha = (String) request.getSession().getAttribute("captcha");
//            if (StringUtils.isEmpty(code)){
//                throw new VerificationCodeException("验证码不能为空！");
//            }
//            if (!genCaptcha.toLowerCase().equals(code.toLowerCase())){
//                throw new VerificationCodeException("验证码输入错误！");
//            }
//            chain.doFilter(request,response);
//        }else{
//            chain.doFilter(request,response);
//        }
//    }
//
//}
